var lastTabId = -1;
var currentTabId = -1;
chrome.commands.onCommand.addListener(function(command) {
	// alert("快捷键加载");
	var commandName = command;
	// alert("commandName:" + commandName );
	if(commandName == "focusInputSearch"){
		chrome.tabs.executeScript({file:"myscript.js"});
	}else{
		exchangeTab();

	}
});

chrome.tabs.onActivated.addListener(function(activeInfo){
	var tabId = activeInfo.tabId;
	// alert("newTabId:" + tabId);
	if(currentTabId != tabId){
		if(currentTabId != -1){
			lastTabId = currentTabId;
			currentTabId = tabId;
		}else{
			currentTabId = tabId;
		}
	}
});


function exchangeTab(){
	// alert("lastId:" + lastTabId + "currentTabId:" + currentTabId);
	if(lastTabId != currentTabId){
		if(lastTabId != -1){
			var tabIndex = -1;
			chrome.tabs.get(lastTabId,function(tab){
				tabIndex = tab.index;
				chrome.tabs.highlight({tabs:(tabIndex)});
			});
			
		}
	}
}
